SOURCE_DIR=source
BIN_DIR=bin
BUILD_DIR=build
DOC_DIR=doc
OBJECTS=$(BUILD_DIR)/common.o $(BUILD_DIR)/mutex.o $(BUILD_DIR)/counter.o $(BUILD_DIR)/network.o
PROGRAMS=$(BIN_DIR)/client $(BIN_DIR)/serv1 $(BIN_DIR)/serv2 $(BIN_DIR)/serv3 $(BIN_DIR)/talk 
CC=gcc
LINKER=gcc
COPTS=-Wall
LOPTS=-Wall



all: $(BUILD_DIR) $(BIN_DIR) $(PROGRAMS)

$(BUILD_DIR): 
	mkdir $(BUILD_DIR)

$(BIN_DIR): 
	mkdir $(BIN_DIR)

package:
	tar -cf marek.kirejczyk.tar $(SOURCE_DIR) $(DOC_DIR)/*.pdf Makefile 

$(BIN_DIR)/client: $(BUILD_DIR)/client.o $(OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

$(BIN_DIR)/serv1: $(BUILD_DIR)/serv1.o $(OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

$(BIN_DIR)/serv2: $(BUILD_DIR)/serv2.o $(OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

$(BIN_DIR)/talk: $(BUILD_DIR)/talk.o $(OBJECTS)
	$(LINKER) $(LOPTS) -g  $^ -lcurses -o $@

$(BIN_DIR)/serv3: $(BUILD_DIR)/serv3.o $(OBJECTS)
	$(LINKER) $(LOPTS) $^ -o $@

clean:
	rm -fr $(BIN_DIR) $(BUILD_DIR) 

$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c 
	$(CC) $(COPTS) -c $^ -o $@

